In [1]:
import pandas as pd

# Font: https://www.idescat.cat/pub/?id=eqvt&n=1636

file = "data/t1636.csv"
df = pd.read_csv(file, skiprows=6)
df.rename(columns={"Unnamed: 0": "Concepte"}, inplace=True)

df.head()
Out[1]:
Concepte Homes. De 16 a 24 anys Homes. De 25 a 44 anys Homes. De 45 a 54 anys Homes. De 55 anys i més Homes. Total Dones. De 16 a 24 anys Dones. De 25 a 44 anys Dones. De 45 a 54 anys Dones. De 55 anys i més Dones. Total Ambdós sexes. De 16 a 24 anys Ambdós sexes. De 25 a 44 anys Ambdós sexes. De 45 a 54 anys Ambdós sexes. De 55 anys i més Ambdós sexes. Total
0 Jornada 7.86 7.22 7.32 7.26 7.29 7.16 7.29 7.34 7.52 7.32 7.50 7.25 7.33 7.37 7.30
1 Flexibilitat d'horaris 7.74 6.63 6.78 7.00 6.78 7.40 6.58 6.55 6.80 6.66 7.56 6.61 6.67 6.92 6.73
2 Temps de descans en la jornada 7.61 6.76 6.98 7.16 6.92 7.34 6.73 6.40 6.90 6.72 7.47 6.75 6.71 7.05 6.83
3 Vacances i permisos 7.59 7.31 7.20 7.56 7.33 7.51 7.34 7.38 7.28 7.35 7.55 7.32 7.28 7.44 7.34
4 Salari 5.97 6.14 6.16 6.06 6.13 6.29 5.89 5.70 5.61 5.84 6.14 6.03 5.95 5.87 5.99
In [2]:
import plotly.graph_objects as go

def add_bullet_chart(data, y):
    fig.add_trace(go.Indicator(
        mode = "number+gauge+delta", value = data["Dones. Total"],
        delta = {"reference": data["Homes. Total"]},
        domain = {"x": [0.2, 1], "y": y},
        title = {"text": f"<b>{data['Concepte']}</b>", 'font': {"size": 14}},
        gauge = {
            "shape": "bullet",
            "axis": {"range": [None, 10]},
            "threshold": {
                "line": {"color": "red", "width": 2},
                "thickness": 0.6,
                "value": data["Homes. Total"]},
            "steps": [
                {"range": [0, 5], "color": "cyan"},
                {"range": [5, 7], "color": "royalblue"}],
            "bar": {"color": "darkblue"}}),            
            )

layout = go.Layout(
    grid = {"rows": 3, "columns": 1},
    height = 400,
    margin = {"t": 50, "b": 50, "l": 40, "r": 0},
)

fig = go.Figure(layout=layout)

add_bullet_chart(df[df["Concepte"] == "Jornada"].iloc[0], [0.65, 0.85])
add_bullet_chart(df[df["Concepte"] == "Activitat desenvolupada"].iloc[0], [0.35, 0.55])
add_bullet_chart(df[df["Concepte"] == "Temps de descans en la jornada"].iloc[0], [0.05, 0.25])

fig.show()